var app = getApp();
Page({
  data: {
    money:0,
    mobile:'',
    cash_account:'',
    cash_money:''


  },
  onLoad: function (options) {
    this.getUserInfo();
  },

  getUserInfo:function()
  {
    let that = this
    wx.request({
      url: app.url + 'weiapp/api/userinfo',
      data: {
        uid: wx.getStorageSync('uid')
      },
      success: function (res) {
        console.log(res)
        that.setData({
          mobile:res.data.data.mobile,
          cash_account:res.data.data.cash_account,
          money:res.data.data.money
        })
      }
    })
  },
  getPhone(even) {
    this.setData({
      mobile: even.detail.value
    })
  },
  getNickName(even) {
    this.setData({
      nickname: even.detail.value
    })
    console.log(even.detail.value)
  },   
  getCashMoney(even) {
    this.setData({
      cash_money: even.detail.value
    })
    console.log(even.detail.value)
  },   
  getCashAccount(even) {
    this.setData({
      cash_account: even.detail.value
    })
    console.log(even.detail.value)
  },    
  postCashMoney()
  {
    if (this.data.money == 0)
    {
      wx.showToast({
        title: '可提现金额为0',
      })
      return;
    }
    if(this.data.mobile.length != 11)
    {
      wx.showToast({
        title: '请输入正确联系方式',
      })
      return;
    }
    if (this.data.cash_account == null) {
      wx.showToast({
        title: '请输入姓名',
      })
      return;
    }    
    if (this.data.nickname == null) {
      wx.showToast({
        title: '请输入支付宝账户',
      })
      return;
    } 
    if (this.data.cash_money == 0 || this.data.cash_money == null ) {
      wx.showToast({
        title: '请输入正确提现金额',
      })
      return;
    } 
    if (this.data.money < this.data.cash_money) {
      wx.showToast({
        title: '金币余额不足',
      })
      return;
    }                
    wx.request({
      url: app.url + 'weiapp/api/saveCashRecord',
      data:{
        uid:wx.getStorageSync('uid'),
        nickname:this.data.nickname,
        cash_account:this.data.cash_account,
        mobile:this.data.mobile,
        cash_money:this.data.cash_money,
        money:this.data.money
      },
      success:function(res)
      {
        console.log(res)
        if(res.data.code == 200)
        {
          wx.showToast({
            title: '提现申请成功',
          })
          setTimeout(function()
          {
            wx.switchTab({
              url: '../index/index',
            })
          },2000)
        }
      }
    })
  } 
})